home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / TEMP / GNU / flex / Miscellane < prev    next >
Text File  |  1995-06-28  |  3KB  |  73 lines

  1. Miscellaneous
  2. Previous: <End-of-file rules=>Endoffiler> * Next: <User variables=>Uservariab> * Up: <Top=>!Root>
  3.  
  4. #Wrap on
  5. {fH3}Miscellaneous macros{f}
  6.  
  7. The macro {fCode}YY\_USER\_ACTION{f} can be defined to provide an
  8. action which is always executed prior to the matched
  9. rule's action.  For example, it could be \#define'd to call
  10. a routine to convert yytext to lower-case.  When
  11. {fCode}YY\_USER\_ACTION{f} is invoked, the variable {fCode}yy\_act{f} gives the
  12. number of the matched rule (rules are numbered starting
  13. with 1).  Suppose you want to profile how often each of
  14. your rules is matched.  The following would do the trick:
  15.  
  16. #Wrap off
  17. #fCode
  18. \#define YY\_USER\_ACTION ++ctr[yy\_act]
  19. #f
  20. #Wrap on
  21.  
  22. where {fCode}ctr{f} is an array to hold the counts for the different
  23. rules.  Note that the macro {fCode}YY\_NUM\_RULES{f} gives the total number
  24. of rules (including the default rule, even if you use {fEmphasis}-s{f}, so
  25. a correct declaration for {fCode}ctr{f} is:
  26.  
  27. #Wrap off
  28. #fCode
  29. int ctr[YY\_NUM\_RULES];
  30. #f
  31. #Wrap on
  32.  
  33. The macro {fCode}YY\_USER\_INIT{f} may be defined to provide an action
  34. which is always executed before the first scan (and before
  35. the scanner's internal initializations are done).  For
  36. example, it could be used to call a routine to read in a
  37. data table or open a logging file.
  38.  
  39. The macro {fEmphasis}yy\_set\_interactive(is\_interactive){f} can be used
  40. to control whether the current buffer is considered
  41. {fEmphasis}interactive{f}.  An interactive buffer is processed more slowly,
  42. but must be used when the scanner's input source is indeed
  43. interactive to avoid problems due to waiting to fill
  44. buffers (see the discussion of the {fEmphasis}-I{f} flag below).  A
  45. non-zero value in the macro invocation marks the buffer as
  46. interactive, a zero value as non-interactive.  Note that
  47. use of this macro overrides {fEmphasis}%option always-interactive{f} or
  48. {fEmphasis}%option never-interactive{f} (see Options below).
  49. {fEmphasis}yy\_set\_interactive(){f} must be invoked prior to beginning to
  50. scan the buffer that is (or is not) to be considered
  51. interactive.
  52.  
  53. The macro {fEmphasis}yy\_set\_bol(at\_bol){f} can be used to control
  54. whether the current buffer's scanning context for the next
  55. token match is done as though at the beginning of a line.
  56. A non-zero macro argument makes rules anchored with
  57.  
  58. The macro {fEmphasis}YY\_AT\_BOL(){f} returns true if the next token
  59. scanned from the current buffer will have '^' rules
  60. active, false otherwise.
  61.  
  62. In the generated scanner, the actions are all gathered in
  63. one large switch statement and separated using {fCode}YY\_BREAK{f},
  64. which may be redefined.  By default, it is simply a
  65. "break", to separate each rule's action from the following
  66. rule's.  Redefining {fCode}YY\_BREAK{f} allows, for example, C++
  67. users to \#define YY\_BREAK to do nothing (while being very
  68. careful that every rule ends with a "break" or a
  69. "return"!) to avoid suffering from unreachable statement
  70. warnings where because a rule's action ends with "return",
  71. the {fCode}YY\_BREAK{f} is inaccessible.
  72.  
  73.